Day twenty-one
Hello everyone, it's Ray!
In my previous article, I mentioned what Git look like if we try to visualize it.
大家好,我是Ray!
前篇文章有淺談到,如果我們將git視覺化之後,大概會長怎麼樣?
As image above, we could see that there are many arrows pointing to last commit and the one before that. It's has everything to do with Git's structure, so I think it's better to pause for a moment to learn Git's struture a little bit before going further usage, and also how Git works when we commit.
圖上可以看到箭頭一直往前指,這關係到git的基礎結構,所以在我們繼續往更深一層的應用介紹之前,我想跟大家分享一下git的結構,以及當我們使用git add增加新檔案,然後commit時,到底git是如何運作的?
Firstly, it's extremely important to learn that what Git truly cares about is the content of files, that said, Git doesn't care about the directory, the name of the files ... etc.
首先,有一點非常重要,Git只在乎檔案的內容,不在乎檔案名稱以及目錄。
Broadingly speaking, Git's structure looks just like trees. Let's learn about it through some animated photos with amazing hand writing.
Hypothetically, let's say that today we add a new file, but we haven't added it into the tracking list. So from Git's view, there is nothing there, as image below:
Git大概是一種樹狀的結構,讓我們通過生動的圖片以及絕美的字跡來將這個重要的概念印在我們的腦海中。假設今天我們在有安裝git的資料夾內新增一個檔案,此時我們尚未將檔案加入追蹤清單,所以在git的眼中,目前是完全沒有東西的。看起來大概是這樣:
Then when we use git add
to add the file into tracking list, it looks like that:
那當我們使用git add
將檔案加到追蹤清單後,看起來就像是這樣:
And then we add another file, and add it into tracking list, it looks like that:
這時我們在新增另外一個檔案,並且加入追蹤清單,看起來大概會是這樣:
Now we use git commit -am "The first commit"
, and a tree object will be created along with a commit object as follows:
此時我們使用git commit -am "the first commit"
,會產生一個新的tree物件,以及commit物件,如下:
Because currently we haven't added a new branch, so the default branch is called 'master'. It looks like the image below:
而目前我們還未增加新的branch,所以預設的bracn為master,整看起來如下圖:
As memntioned above, currently we only have a branch, so the 'HEAD' is pointing to the 'master' branch, as follows:
如上所敘,目前我們只有一個branch,所以我們的head目前指向名為master的branch,如下:
I will do my best to describe this kind of bottom concept as explicitly as I can, so in my later articles, I will talk about what Git's four objects are, and how it truly works when we commit, make branch, add a tag and even switch among different branches.
底層部分的觀念我會盡我所能地描述得比較清楚一點,所以之後的文章會介紹當我下了一個新的commit之後,實際上的流程會是怎麼樣,以及什麼是Git裡的各種物件。
By the way, I really found that my English hand writing was so amazing, to be more prcise, what a chicken scratch, fortunatly which also indicates that I'm absolutely a Taiwan native.
還有我發現我的英文字寫得好醜,這代表我是一個純正的台灣人,沒事沒事。
See you guys tomorrow.
我們明天見!